package controller

import "github.com/astaxie/beego"

type BaseController struct {
	beego.Controller
}

type response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

func (c BaseController) success(data interface{}) {
	r := response{
		Code:    200,
		Message: "success",
		Data:    data,
	}

	c.Data["json"] = r
	c.ServeJSON()
}

func (c BaseController) fail(msg string) {
	r := response{
		Code:    -1,
		Message: msg,
	}

	c.Data["json"] = r
	c.ServeJSON()
}